package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageDTO;
import com.sky.entity.Setmeal;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealMapper {

    // 根据分类id统计套餐数量
    @Select("select count(*) from sky_take_out.setmeal where category_id=#{cid}")
    Integer countByCategoryId(Long cid);

    // 条件查询
    List<SetmealVO> findList(SetmealPageDTO dto);

    // 新增
    @AutoFill("insert")
    @Insert("insert into sky_take_out.setmeal values (null,#{categoryId},#{name},#{price},#{status},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    void save(Setmeal setmeal);

    // 根据id查询套餐+分类名称
    @Select("select s.*,c.name categoryName from sky_take_out.setmeal s left join sky_take_out.category c on s.category_id = c.id where s.id=#{id}")
    SetmealVO findById(Long id);

    @AutoFill("update")
    void update(Setmeal setmeal);
    //批量删除套餐
    void deleteByIds(Long[] ids);
}